import AddTestCasePage from "./AddTestCasePage.vue";

export default {
  watch: {
    projectId: function (newProjectId) {
      this.getList();
      this.caseShow = false;
    }
  },
  computed: {
    projectId: function () {
      return this.$store.getters.getProjectId;
    },
  },
  components: {AddTestCasePage},
  data() {
    return {
      title: "新增测试用例集",
      dialogFormVisibleG: false,
      dialogFormVisible: false,
      caseShow: false,
      search: "",
      groupList: [],
      testCaseList: [],
      groupName: "",
      remark: "",
      groupIdByNow: 0,
      formLabelWidth: "100px",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    test(index) {
      console.log(index.row);
    },
    getList() {
      this.$group
        .list({projectId: this.$store.getters.getProjectId})
        .then((res) => {
          if (res.code == 200) {
            this.groupList = res.data;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getCaseList() {
      this.$group
        .caseList({testGroupId: this.groupIdByNow})
        .then((res) => {
          if (res.code == 200) {
            this.testCaseList = res.data;
            this.caseShow = true;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    rowClick(row, colum, envent) {
      // console.log("row:",row);
      // console.log("colum:",colum);
      // console.log("envent:",envent);
      this.groupIdByNow = row.id;
      this.getCaseList();
    },
    addTestCase() {
      this.dialogFormVisible = true;
    },
    handleDelete(index, value) {
      this.$group.deleteCase({id: value.id}).then((res) => {
        if (res.code == 200) {
          this.getCaseList();
        }
      });
    },
    off() {
      this.dialogFormVisible = false;
      this.getCaseList();
    },
    addGroup() {
      this.$group.add({
        name: this.groupName,
        remark: this.remark,
        projectId: this.$store.getters.getProjectId
      }).then((res) => {
        if (res.code == 200) {
          this.dialogFormVisibleG = false;
          this.getList();
          this.$message({
            showClose: true,
            message: res.message,
            type: "success",
          })
        } else {
          this.$message.error(res.message);
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    dj() {
      this.addGroup();
    }
  },
}
